/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.crm.controller;

import javax.faces.event.ActionEvent;
import java.util.*;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import queenb.net.entitybean.B630;
import queenb.net.entitybean.N100;
import queenb.web.controller.QueenbController;
import queenb.web.crm.inteface.B630Inf;
import queenb.web.crm.store.B630Store;
import queenb.web.crm.store.CustomerStore;
import queenb.web.store.EmployeeStore;
import queenb.web.util.ComboboxUtil;
import queenb.web.util.ContextUtil;
import queenb.web.util.SessionProvider;
import queenb.web.util.Util;

/**
 *
 * @author Nguyen Hung
 */
public class B630Controller extends QueenbController {

    // Khai bao bien controller
    private int pb630;
    private String bv631;//Title
    private int fc500 = 1;//finish
    private Date bd632;//begin
    private Date bd633;//end
    private int bn634;//
    private int bn640;
    private String bv635;
    private String bv636;
    private String bc637;//viet tat
    private String bc638 = "A";
    private int fb670;
    private int fh000;
    private int fh200;
    private int fk100;// id company
    private String companyName;
    private int fb050;//project
    private int fn100;
    private String fq101;//nguoi dam trach
    private int fn850dt = 3;
    private int pb670;//id muc dich
    private int fq100;//nhan vien dai dien cho khach hang coty/id cua khach hang ca nhan
    private String kv103;//ho ten khach hang ca nhan
    private String bv639 = "AC";
    private String pageRidiect;
    private B630Inf b630Inf;
    private boolean flagcus = false;
    private boolean flagcom = false;
    private String displaycus;
    private String displaycom;
    private List<B630> listB630 = null;
    private List<SelectItem> listComB670 = null;
    private List<B630> listOfDateCM = new ArrayList<B630>();// list all emp
    private List<B630> listOfDateCOM = new ArrayList<B630>();
    private List<SelectItem> combB050 = new ArrayList<SelectItem>();// danh sách dự án
    private List<SelectItem> selectItemN900 = new ArrayList<SelectItem>();
    private List<SelectItem> selectCombN850 = new ArrayList<SelectItem>();
    private List<SelectItem> selectComN100D = new ArrayList<SelectItem>();
    ComboboxUtil comboboxUtil = new ComboboxUtil();
    private B630Store b630Store;
    private String NV106;// nhan viên
    private int typeSearch = 0;// tim kiem
    private String keySearch;
    private int pb650;//note id
    private String bv651;//title note
    private String bv652;//note
    private String bl667;//emp update
    private boolean checkComplete;// hoan thanh cham soc kahch hang
    private String title;
    private List<B630> listSelectedCM = new ArrayList<B630>();// da chon
    private List<B630> listSelectedCOM = new ArrayList<B630>();
    //paging
    private int Offset = 0;
    private int Limit = 30;
    private int totalrow; // tong so dong
    private int totalpage; // tong so trang
    private int current; // traung hien tai
    static private int numrow = 30; // so dong tren 1 trang
    private int start; // bat dau lay tu record
    private int end; // lay tu record so
    private int startpage = 1; // page bat dau
    private int endpage = 1;   // page ket thuc
    private String pagename = "";
    private int totalcurent;
    //
    private List<SelectItem> lstEmpByID = new ArrayList<SelectItem>();
    private int fn850;
    private String loginEmp;
    private String userAction;
    private int flagFN850;
    private List<N100> listEmployee;
    private EmployeeStore employeeStore;
    private String actionChange = "cm";
    private List<B630> listhistoryCustomer = new ArrayList<B630>();// list all emp

    public B630Controller() {
        if (SessionProvider.getSessionMapValue("groupID") != null) {
            fn850 = Integer.parseInt(SessionProvider.getSessionMapValue("groupID").toString());
        }
        if (SessionProvider.getSessionMapValue("emp") != null) {
            loginEmp = SessionProvider.getSessionMapValue("emp").toString();
            userAction = loginEmp;
        }
        Object objflagFN850 = getRequest().getParameter("flagFN850");
        if (objflagFN850 != null) {
            flagFN850 = Integer.parseInt(objflagFN850.toString());
        }
        b630Store = new B630Store();

        getKapiMenu().setAdmin(false);
        getKapiMenu().setMainmenu1("m123");
        Object kh = getRequest().getParameter("kh");
        if (kh != null) {
            if (kh.equals("CM")) {
                Object listselect = SessionProvider.getSessionMapValue("listSelectedB630CM");
                if (listselect == null) {
                    //SessionProvider.setSessionMapValue("listSelectedEx", listSelected);
                    SessionProvider.setSessionMapValue("listSelectedB630CM", listSelectedCM);
                } else {
                    try {
                        listSelectedCM = (List<B630>) listselect;
                    } catch (Exception e) {
                        listSelectedCM = new ArrayList<B630>();
                    }
                }
                if (listselect != null) {
                }

                Object listBean = SessionProvider.getSessionMapValue("listB630CM");
                if (listBean == null) {
                    SessionProvider.setSessionMapValue("listB630CM", listOfDateCM);
                } else {
                    try {
                        System.out.println("D:-  set listB630CM: " + listOfDateCM.size());
                        listOfDateCM = (List<B630>) listBean;
                    } catch (Exception e) {
                        listOfDateCM = new ArrayList<B630>();
                    }
                }
            } else if (kh.equals("COM")) {
                Object listselect = SessionProvider.getSessionMapValue("listSelectedB630COM");
                if (listselect == null) {
                    //SessionProvider.setSessionMapValue("listSelectedEx", listSelected);
                    SessionProvider.setSessionMapValue("listSelectedB630COM", listSelectedCOM);
                } else {
                    try {
                        listSelectedCOM = (List<B630>) listselect;
                    } catch (Exception e) {
                        listSelectedCOM = new ArrayList<B630>();
                    }
                }
                if (listselect != null) {
                }

                Object listBean = SessionProvider.getSessionMapValue("listB630COM");
                if (listBean == null) {
                    SessionProvider.setSessionMapValue("listB630COM", listOfDateCOM);
                } else {
                    try {
                        System.out.println("D:-  set listB630COM: " + listOfDateCOM.size());
                        listOfDateCOM = (List<B630>) listBean;
                    } catch (Exception e) {
                        listOfDateCOM = new ArrayList<B630>();
                    }
                }
            }

        }
        Object action = getRequest().getParameter("action");
        Object objFQ100 = getRequest().getParameter("id");//get param id cua khach hang ca nhan
        Object fq100A = getRequest().getParameter("fq100");//get param id cua khach hang ca nhan
        Object objFk100 = getRequest().getParameter("itemid");//get id cong ty
        Object objfb670 = getRequest().getParameter("fb670");
        Object objPb630 = getRequest().getParameter("pb630");
        Object objPage = getRequest().getParameter("page");
        Object objDateOf = getRequest().getParameter("dateof");
        Object objStatus = getRequest().getParameter("status");// trang thai haon thanh 
        Object objDash = getRequest().getParameter("fk100");
        Object objPn100 = getRequest().getParameter("pn100");
        Object objTitle = getRequest().getParameter("title");
        Object objFn100CN = getRequest().getParameter("fn100CN");
        System.out.println("-------dateof ----------" + objDateOf);
        try {
            if (objPage.equals("customer.jsp")) {
                this.displaycus = "block;";
                this.displaycom = "none;";

            }
            if (objPage.equals("cuscompany.jsp")) {
                this.displaycus = "none;";
                this.displaycom = "block;";
            }
        } catch (Exception ex) {
        }
        System.out.println("---page ---" + objPage);
        if (objPage != null) {
            this.pageRidiect = objPage.toString();

        }
        if (objFk100 != null) {
            this.fk100 = Integer.parseInt(objFk100.toString());
        }
        if (objFQ100 != null) {
            this.fq100 = Integer.parseInt(objFQ100.toString());
        }
        if (objfb670 != null) {
            this.fb670 = Integer.parseInt(objfb670.toString());
        }
        if (fq100A != null) {
            this.fq100 = Integer.parseInt(fq100A.toString());
        }
        if (action != null) {
            if (action.equals("add")) {
                this.fq100 = Integer.parseInt(fq100A.toString());

            } else if (action.equals("addNote")) {
                if (objFn100CN != null) {
                    fn100 = Integer.parseInt(objFn100CN.toString());
                }
                if (objTitle != null) {
                    title = objTitle.toString();
                }
                this.pb630 = Integer.parseInt(objPb630.toString());
            } else if (action.equals("edit")) {
                this.pb630 = Integer.parseInt(objPb630.toString());
                getListB630Detail(pb630);
            } else if (action.equals("editCOM")) {
                this.pb630 = Integer.parseInt(objPb630.toString());
                getListB630DetailCOM(pb630);
            } else if (action.equals("editB650")) {
                if (objTitle != null) {
                    title = objTitle.toString();
                }
                this.pb630 = Integer.parseInt(objPb630.toString());
                Object objPb650 = getRequest().getParameter("pb650");
                if (objPb650 != null) {
                    this.pb650 = Integer.parseInt(objPb650.toString());
                    getListB650Detail(pb650);
                }


            } else if (action.equals("loadB650")) {
                if (objTitle != null) {
                    title = objTitle.toString();
                }
                this.pb630 = Integer.parseInt(objPb630.toString());
            } else if (action.equals("delete")) {
                this.pb630 = Integer.parseInt(objPb630.toString());

            } else if (action.equals("checkComplete")) {
                this.pb630 = Integer.parseInt(objPb630.toString());
                this.bc638 = objStatus.toString();
                System.out.println("=========get var -------" + pb630 + bc638);
                checkComplete(pb630, bc638);
            } else if (action.equals("addDash")) {
                fk100 = Util.parseInt(objDash);
                fq100 = Util.parseInt(objPn100);
                System.out.println("=========get var ON DashBoard -------" + fk100 + fn100);

            } else if (action.equals("addCusp100")) {
                if (kh.equals("CM")) {
                    Object f = getRequest().getParameter("p100");
                    Object s = getRequest().getParameter("valueC");

                    System.out.println("sssssssssssssssss----------------------" + f + "===============" + s);
                    if ("false".equals(s.toString())) {
                        for (int i = 0; i < listSelectedCM.size(); i++) {
                            if (listSelectedCM.get(i).getPb630() == Integer.parseInt(f.toString())) {
                                listSelectedCM.remove(i);
                                break;
                            }
                        }
                    } else {
                        for (int i = 0; i < listOfDateCM.size(); i++) {
                            if (listOfDateCM.get(i).getPb630() == Integer.parseInt(f.toString())) {
//                            if (list.get(i).getNv105() != null && list.get(i).getNv105() != "" && list.get(i).getNv105().contains("@")) {
                                if (!checkExistList(listSelectedCM, Integer.parseInt(f.toString()))) {
                                    listSelectedCM.add(listOfDateCM.get(i));
                                    break;
                                }

//                            }
                            }
                        }
                    }
                    SessionProvider.setSessionMapValue("listSelectedB630CM", listSelectedCM);
                    SessionProvider.setSessionMapValue("listB630CM", listOfDateCM);
                    System.out.println("<><><><><><><><><><><><><><><><><><><>-----" + f + "....." + listSelectedCM.size());
                } else if (kh.equals("COM")) {
                    Object f = getRequest().getParameter("p100");
                    Object s = getRequest().getParameter("valueC");

                    System.out.println("sssssssssssssssss----------------------" + f + "===============" + s);
                    if ("false".equals(s.toString())) {
                        for (int i = 0; i < listSelectedCOM.size(); i++) {
                            if (listSelectedCOM.get(i).getPb630() == Integer.parseInt(f.toString())) {
                                listSelectedCOM.remove(i);
                                break;
                            }
                        }
                    } else {
                        for (int i = 0; i < listOfDateCOM.size(); i++) {
                            if (listOfDateCOM.get(i).getPb630() == Integer.parseInt(f.toString())) {
//                            if (list.get(i).getNv105() != null && list.get(i).getNv105() != "" && list.get(i).getNv105().contains("@")) {
                                if (!checkExistList(listSelectedCOM, Integer.parseInt(f.toString()))) {
                                    listSelectedCOM.add(listOfDateCOM.get(i));
                                    break;
                                }

//                            }
                            }
                        }
                    }
                    SessionProvider.setSessionMapValue("listSelectedB630COM", listSelectedCOM);
                    SessionProvider.setSessionMapValue("listB630COM", listOfDateCOM);
                    System.out.println("<><><><><><><><><><><><><><><><><><><>-----" + f + "....." + listSelectedCOM.size());
                }

                //check All
            } else if (action.equals("addAllCusp100")) {
                if (kh.equals("CM")) {
                    Object va = getRequest().getParameter("boool");
                    if ("true".equals(va.toString())) {
                        listSelectedCM.clear();
                        for (int i = 0; i < listOfDateCM.size(); i++) {
//                        if (list.get(i).getNv105() != null && list.get(i).getNv105() != "" && list.get(i).getNv105().contains("@")) {
                            listSelectedCM.add(listOfDateCM.get(i));
//                        }
                        }
                    } else {
                        listSelectedCM.clear();
                    }
                    SessionProvider.setSessionMapValue("listSelectedB630CM", listSelectedCM);
                    SessionProvider.setSessionMapValue("listB630CM", listOfDateCM);
                } else if (kh.equals("COM")) {
                    Object va = getRequest().getParameter("boool");
                    if ("true".equals(va.toString())) {
                        listSelectedCOM.clear();
                        for (int i = 0; i < listOfDateCOM.size(); i++) {
//                        if (list.get(i).getNv105() != null && list.get(i).getNv105() != "" && list.get(i).getNv105().contains("@")) {
                            listSelectedCOM.add(listOfDateCOM.get(i));
//                        }
                        }
                    } else {
                        listSelectedCOM.clear();
                    }
                    SessionProvider.setSessionMapValue("listSelectedB630COM", listSelectedCOM);
                    SessionProvider.setSessionMapValue("listB630COM", listOfDateCOM);
                }
            } else if (action.equals("clear")) {
                System.out.println("clear list B630 !");
                listSelectedCM.clear();
                listSelectedCOM.clear();
                SessionProvider.setSessionMapValue("listSelectedB630CM", null);
                SessionProvider.setSessionMapValue("listSelectedB630COM", null);
            } else if (action.equals("birthday")) {
                setActionChange("birthday");
            }
//            else if (objAction.equals("sendMoreSMS")) {
//                Object action = getRequest().getParameter("mv302");
//                if (objMV302 != null) {
//                    this.mv302 = objMV302.toString();//noi dung ti nnhan
//                }
//                Object objMV305 = getRequest().getParameter("mv305");
//                if (objMV305 != null) {
//                    this.mv305 = objMV305.toString();//muc dich
//                }
//                if (listselect != null) {
//                    System.out.println("---------list size ----------" + listSelected.size());
//                    Iterator iterator = listSelected.iterator();
//                    M300Store m300Store = new M300Store();
//                    this.mn314 = m300Store.selectIDM300("M300", "MN314", getLogin().getModule(), 1);
//                    while (iterator.hasNext()) {
//                        N100 n100 = (N100) iterator.next();
//                        System.out.println("---------insert ----------" + n100.getVv051() + "---" + n100.getVv052());
//                        try {
//                            java.sql.Timestamp date = new java.sql.Timestamp(new Date().getTime());
//                            System.out.println("---dien thoai---" + n100.getNv958());
//                            if (n100.getNv958() != null) {
//                                m300Store.updateM300(0, getLogin().getModule(), getLogin().getCompanyNo(), n100.getPn100(), date, this.getMv302(), this.getMv303(), n100.getNv958(), this.getMv305(), n100.getVv051(), this.getMn314(), getLogin().getUserName());
//                            }
//                        } catch (Exception ex) {
//                        }
//                    }
//                }
//            }
            if (action.equals("COM") || action.equals("CM")) {
                SessionProvider.removeSessionMapValue("TYPE");

            }


        }
        if (SessionProvider.getSessionMapValue("listSelectedB630CM") != null) {
            List<B630> a = (List<B630>) SessionProvider.getSessionMapValue("listSelectedB630CM");
            System.out.println("D:- listSelectedB630CM : " + a.size());
            for (B630 b630 : a) {
                System.out.println("-- " + b630.toString());
            }
        } else {
            System.out.println("D:- listSelectedB630CM :  null");
        }

        if (SessionProvider.getSessionMapValue("listSelectedB630COM") != null) {
            List<B630> a = (List<B630>) SessionProvider.getSessionMapValue("listSelectedB630COM");
            System.out.println("D:- listSelectedB630COM : " + a.size());
            for (B630 b630 : a) {
                System.out.println("-- " + b630.toString());
            }
        } else {
            System.out.println("D:- listSelectedB630COM :  null");
        }


        //paging
        int a;
        System.out.println("D:-- listEmployee is not null ");
        Object ppage = getRequest().getParameter("p");
        if (ppage != null) {
            try {
                a = Integer.parseInt(ppage.toString());
            } catch (Exception ex) {
                a = 1;
            }
            if (a == 1) {
                setCurrent(1);
                setOffset(0);
                System.out.println("D:-- setOffset: " + 0);
            } else {
                setCurrent(a);
                setOffset((a - 1) * Limit);
                System.out.println("D:-- setOffset: " + ((a - 1) * Limit));
            }
            System.out.println("D:-- page: " + a);

        } else {
            SessionProvider.setSessionMapValue("typeSearchCSKH", null);
            SessionProvider.setSessionMapValue("keySearchCSKH", null);
            SessionProvider.setSessionMapValue("typeSearchCSKHCT", null);
            SessionProvider.setSessionMapValue("keySearchCSKHCT", null);
            setCurrent(1);
            setOffset(0);
            System.out.println("D:-- page: 1");
        }



    }

    public void reloadWork() {
        userAction = getLogin().getUserName();
        System.out.println("==================TYPE SEARCH---" + getTypeSearch());
        SessionProvider.setSessionMapValue("TYPE", typeSearch);
        System.out.println(" ----------D:   Typesearch: " + typeSearch);
        System.out.println(" ----------D:   keysearch: " + keySearch);
        SessionProvider.setSessionMapValue("typeSearchCSKH", typeSearch);
        SessionProvider.setSessionMapValue("keySearchCSKH", keySearch);
    }

    public void reloadWorkCOM() {
        userAction = getLogin().getUserName();
        System.out.println("==================TYPE SEARCH---" + getTypeSearch());
        SessionProvider.setSessionMapValue("TYPE", typeSearch);
        System.out.println(" ----------D:   Typesearch: " + typeSearch);
        System.out.println(" ----------D:   keysearch: " + keySearch);
        SessionProvider.setSessionMapValue("typeSearchCSKHCT", typeSearch);
        SessionProvider.setSessionMapValue("keySearchCSKHCT", keySearch);

    }

    public void checkComplete(int id, String status) {
        try {
            CustomerStore customerStore = new CustomerStore();
            int rs = customerStore.updateColumnN100(null, "B630", "BV638", status, "PB630", id, getLogin().getUserName());
            System.out.println("==================COMPLETE AFTER---" + rs);
        } catch (Exception e) {
        }
    }

    public void updateByB630() {
        System.out.println("---updateByB630 --- ");
        String startDate = "";
        String startTimer = "";
        String endTimer = "";
        String endDate = "";
        getBuffer().append("");
        try {
            startTimer = ContextUtil.getRequestParameter("timepicker");
            if (startTimer == "") {
                String h = String.valueOf(new Date().getHours());
                String m = String.valueOf(new Date().getMinutes());
                startTimer = h + ":" + m;
            }
            endTimer = ContextUtil.getRequestParameter("timepicker2");
            if (endTimer == "") {
                String h = String.valueOf(new Date().getHours());
                String m = String.valueOf(new Date().getMinutes());
                endTimer = h + ":" + m;
            } else if (endTimer == null) {
                String h = String.valueOf(new Date().getHours());
                String m = String.valueOf(new Date().getMinutes());
                endTimer = h + ":" + m;
            }
            String startDateDemo = ContextUtil.getRequestParameter("leavedate1");
            String demo = startDateDemo.substring(0, 2);
            String demo2 = startDateDemo.substring(3, 5);
            String demo3 = startDateDemo.substring(6, 10);
            String datetotal = demo2 + "/" + demo + "/" + demo3;

            System.out.println("---================  --- " + demo + "===" + demo2 + "====" + demo3 + "====" + datetotal);
            String startDateDemo1 = ContextUtil.getRequestParameter("leavedate2");
            String demo4 = startDateDemo1.substring(0, 2);
            String demo5 = startDateDemo1.substring(3, 5);
            String demo6 = startDateDemo1.substring(6, 10);
            String datetotal1 = demo5 + "/" + demo4 + "/" + demo6;

            System.out.println("---================  --- " + demo + "===" + demo2 + "====" + demo3 + "====" + datetotal1);

            startDate = datetotal + " " + startTimer;
            endDate = datetotal1 + " " + endTimer;
            System.out.println("---start date --- " + startDate);

            System.out.println("---end date --- " + endDate);

            java.sql.Timestamp date1 = null;
            java.sql.Timestamp date2 = null;
            if (!startDate.equals("")) {

                java.util.Date date3 = new Date(startDate);
                //  Date startDate1= Util.parseDate(startDate, "dd/MM/yyyy");

                date1 = new java.sql.Timestamp(date3.getTime());

            }
            if (!endDate.equals("")) {
                java.util.Date date4 = new Date(endDate);

                System.out.println("---start date time ---AaAAAAA------- " + date4);

                date2 = new java.sql.Timestamp(date4.getTime());


            }

            System.out.println("---start date time --- " + date1);
            System.out.println("---end date  time--- " + date2);


            System.out.println("==========PAGE  ---" + pageRidiect + "--insert b630----" + this.pb630 + "," + this.bv631 + "," + this.fc500 + "," + date1 + ","
                    + date2 + "," + 0 + "," + null + "," + this.bv636 + ","
                    + this.bc637 + "," + null + "," + this.bv639 + "," + 1 + "," + this.fb670 + "," + getLogin().getModule() + ","
                    + getLogin().getCompanyNo() + "," + this.fk100 + "," + this.fb050 + "," + this.fn100 + ","
                    + this.fq100 + "," + getLogin().getUserName());
            int roweffect = b630Inf.updateByB630(this.pb630, this.bv631, this.fc500, date1,
                    date2, 0, bv635, this.bv636,
                    this.bc637, bc638, this.bv639, 1, this.fb670, getLogin().getModule(),
                    getLogin().getCompanyNo(), this.fk100, this.fb050, this.NV106,
                    fq100, getLogin().getUserName());


            showGlobalReport(true, getResourceString("datasavesuccessful"));
            if (pageRidiect.equals("customer.jsp")) {

                sendRedirectURL(pageRidiect, fq100, 4);
            } else if (pageRidiect.equals("customerExpand.jsp")) {
                sendRedirect("customerexpand.jsp");
            } else if (pageRidiect.equals("customer.jsp")) {
                sendRedirect("customer.jsp");
            } else if (pageRidiect.equals("workChargeCM.jsp")) {
                sendRedirect("workChargeCM.jsp");
            } else if (pageRidiect.equals("workChargeCOM.jsp")) {
                sendRedirect("workChargeCOM.jsp");
            }else if(pageRidiect.equals("supplier.jsp")){
                sendRedirect("supplier.jsp");
            }else {
                sendRedirectURL(pageRidiect, fk100, 5);
                System.out.println("fq100================" + fq100 + "---fk100--" + fk100);
            }
        } catch (Exception ex) {
            showGlobalReport(true, getResourceString("datasuccessfail"));
            sendRedirect(pageRidiect);
            System.out.println("----------errrrrooooo----------" + ex.getMessage());
        }

    }

    public void deleteB630() {
        System.out.print("thong tin delete--" + fn100 + "," + getFk100() + "---" + getPb630() + "---" + fq100);
        try {
            int roweffect = b630Inf.deleteByB630i(this.pb630, getLogin().getUserName());
            showGlobalReport(true, getResourceString("datasavesuccessful"));

            if (pageRidiect.equals("customer.jsp")) {
                System.out.println("fq100================" + fq100 + "---fk100--" + fk100);
                sendRedirectURL(pageRidiect, fq100, 4);
            } else {
                sendRedirectURL(pageRidiect, fk100, 5);
            }
        } catch (Exception ex) {

            showGlobalReport(true, getResourceString("datasuccessfail"));
            sendRedirectURL("customer.jsp", fq100, 4);

        }
    }

    public List<B630> getListAllN630itemCN() {
        try {
            System.out.println("---Khách hhhhhhhhhhhhhhhh------" + fk100);
            if (fk100 != 0) {
                listOfDateCM = b630Store.getListAllB630COM(this.getPb630(), null, null, this.getBv639(), this.getBn640(), this.getFc500(), 0, getLogin().getModule(), getLogin().getCompanyNo(), fk100, getLogin().getUserName());
            } else if (fq100 != 0) {
                System.out.println("---Khách hàng cá nhân--" + fq100 + "--getListB630CN----" + this.getPb630() + "," + null + "," + null + "," + this.getBv639() + "," + this.getBn640() + "," + this.getFc500() + "," + this.getFb670() + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFk100() + "," + this.getFb050() + "," + this.getFn100() + "," + getLogin().getUserName());
                listOfDateCM = b630Store.getListB630CN(this.getPb630(), null, null, this.getBv639(), this.getBn640(), this.getFc500(), 0, getLogin().getModule(), getLogin().getCompanyNo(), 0, 0, this.fq100, getLogin().getUserName());
            }



            return listOfDateCM;
        } catch (Exception e) {
            return null;
        }

    }

    public List<B630> getListAllN630COM() {
        List<B630> list = null;
        try {
            int id = 0;

            if (SessionProvider.getSessionMapValue("TYPE") != null) {
                id = Util.parseInt(SessionProvider.getSessionMapValue("TYPE"));
            }
            Object o = SessionProvider.getSessionMapValue("typeSearchCSKH");
            if (o != null) {
                int type;
                try {
                    type = Integer.parseInt(o.toString());
                } catch (Exception e) {
                    type = 0;
                }
                setTypeSearch(type);

            }

            Object o2 = SessionProvider.getSessionMapValue("keySearchCSKH");
            if (o2 != null) {
                setKeySearch(o2.toString());



            }
            B630 b630;

            if (id == 0) {
                System.out.println("-------id 0----" + this.getPb630() + "," + null + "," + null + "," + this.getBv639() + "," + this.getBn640() + "," + this.getFc500() + "," + this.getFb670() + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFk100() + "," + this.getFb050() + "," + this.getFn100() + "," + userAction);
                list = b630Store.getListAllB630COM(this.getPb630(), null, null, this.getBv639(), this.getBn640(), this.getFc500(), 0, getLogin().getModule(), getLogin().getCompanyNo(), this.getFk100(), userAction);

            } else if (id == 1) {
                System.out.println("-------is 1----" + this.getPb630() + "," + null + "," + null + "," + this.getBv639() + "," + this.getBn640() + "," + this.getFc500() + "," + this.getFb670() + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFk100() + "," + this.getFb050() + "," + this.getFn100() + "," + getLogin().getUserName());
                list = b630Store.getListAllB630COM(this.getPb630(), null, null, this.getBv639(), this.getBn640(), this.getFc500(), 3, getLogin().getModule(), getLogin().getCompanyNo(), this.getFk100(), getLogin().getUserName());

            } else if (id == 2) {
                System.out.println("-------id 2----" + this.getPb630() + "," + null + "," + null + "," + this.getBv639() + "," + this.getBn640() + "," + this.getFc500() + "," + this.getFb670() + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFk100() + "," + this.getFb050() + "," + this.getFn100() + "," + getLogin().getUserName());
                list = b630Store.getListAllB630COM(this.getPb630(), null, null, this.getBv639(), this.getBn640(), this.getFc500(), 5, getLogin().getModule(), getLogin().getCompanyNo(), this.getFk100(), getLogin().getUserName());

            } else if (id == 3) {
                System.out.println("-------id 3----" + this.getPb630() + "," + null + "," + null + "," + this.getBv639() + "," + this.getBn640() + "," + this.getFc500() + "," + this.getFb670() + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFk100() + "," + this.getFb050() + "," + this.getFn100() + "," + getLogin().getUserName());
                list = b630Store.getListAllB630COM(this.getPb630(), null, null, this.getBv639(), this.getBn640(), this.getFc500(), 6, getLogin().getModule(), getLogin().getCompanyNo(), this.getFk100(), getLogin().getUserName());

            } else if (id == 4) {
                System.out.println("-------id 4----" + this.getPb630() + "," + null + "," + null + "," + this.getBv639() + "," + this.getBn640() + "," + this.getFc500() + "," + this.getFb670() + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFk100() + "," + this.getFb050() + "," + this.getFn100() + "," + getLogin().getUserName());
                list = b630Store.getListB630CCO(this.getPb630(), null, null, this.getBv639(), this.getBn640(), this.getFc500(), getLogin().getModule(), getLogin().getCompanyNo(), this.getFk100(), getLogin().getUserName());

            }

            //paging
            int t;
            Object obj = SessionProvider.getSessionMapValue("totalcurentCSKHCT");
            if (obj != null) {
                try {
                    t = Integer.parseInt(obj.toString());
                } catch (Exception e) {
                    t = 0;
                }
                totalcurent = t;
            } else {
                totalcurent = 0;
            }

            setTotalrow(totalcurent);

            listOfDateCOM = list;
            SessionProvider.setSessionMapValue("listB630COM", listOfDateCOM);
            return listOfDateCOM;
        } catch (Exception e) {
            list = new ArrayList<B630>();
            return null;
        }


    }

    public void getListB630DetailCOM(int id) {
        try {
            try {
                List<B630> listB630Edit = getListAllN630COM();
                if (listB630Edit.size() > 0) {
                    for (int i = 0; i < listB630Edit.size(); i++) {
                        if (listB630Edit.get(i).getPb630() == id) {
                            this.bv631 = listB630Edit.get(i).getBv631();
                            this.bv635 = listB630Edit.get(i).getBv635();
                            this.bv636 = listB630Edit.get(i).getBv636();
                            this.bd632 = listB630Edit.get(i).getBd632();
                            this.bd633 = listB630Edit.get(i).getBd633();
                            this.fb050 = listB630Edit.get(i).getFb050();
                            this.fb670 = listB630Edit.get(i).getFb670();
                            this.fq100 = listB630Edit.get(i).getFq100();

                            //this.fn850dt = listB630Edit.get(i).get
                            this.fk100 = listB630Edit.get(i).getFk100();
                            System.out.println("------- OUT---" + fk100 + fq100);
                            break;
                        }
                    }
                }
            } catch (Exception ex) {
                System.out.println("Error when getDetailEditN850. ERROR CODE: " + ex.getMessage());
            }
        } catch (Exception e) {
        }
    }

    public List<B630> getListAllN630() {
        try {
            int id = 0;
            if (SessionProvider.getSessionMapValue("TYPE") != null) {
                id = Util.parseInt(SessionProvider.getSessionMapValue("TYPE"));
            }
            Object o = SessionProvider.getSessionMapValue("typeSearchCSKH");
            if (o != null) {
                int type;
                try {
                    type = Integer.parseInt(o.toString());
                } catch (Exception e) {
                    type = 0;
                }
                setTypeSearch(type);

            }

            Object o2 = SessionProvider.getSessionMapValue("keySearchCSKH");
            if (o2 != null) {
                setKeySearch(o2.toString());



            }
            B630 b630;
            if (id != 4) {
                System.out.println("-------getListB630CN----" + id + "--" + this.getPb630() + "," + null + "," + null + "," + this.getBv639() + "," + this.getBn640() + "," + this.getFc500() + "," + id + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFk100() + "," + this.getFb050() + "," + this.getFn100() + "," + userAction);
                listOfDateCM = b630Store.getListB630CN(this.getPb630(), null, null, this.getBv639(), this.getBn640(), this.getFc500(), id, getLogin().getModule(), getLogin().getCompanyNo(), 0, 0, fq100, userAction);

            } else if (id == 4) {
                System.out.println("-------getListB630CNO----" + id + "--" + this.getPb630() + "," + null + "," + null + "," + this.getBv639() + "," + this.getBn640() + "," + this.getFc500() + "," + this.getFb670() + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFk100() + "," + this.getFb050() + "," + this.getFn100() + "," + getLogin().getUserName());
                listOfDateCM = b630Store.getListB630CNO(this.getPb630(), null, null, this.getBv639(), this.getBn640(), this.getFc500(), getLogin().getModule(), getLogin().getCompanyNo(), 0, 0, 0, getLogin().getUserName());

            }
            System.out.println("listOfDateCM size-:" + listOfDateCM.size());
            //paging
            int t;
            Object obj = SessionProvider.getSessionMapValue("totalcurentCSKH");
            if (obj != null) {
                try {
                    t = Integer.parseInt(obj.toString());
                } catch (Exception e) {
                    t = 0;
                }
                totalcurent = t;
            } else {
                totalcurent = 0;
            }

            setTotalrow(totalcurent);
            SessionProvider.setSessionMapValue("listB630CM", listOfDateCM);
            return listOfDateCM;
        } catch (Exception e) {
            return null;
        }

    }

    public List<N100> getN100Birthday() {
        try {
            employeeStore = new EmployeeStore();
            Calendar c = Calendar.getInstance();
            c.setTime(new Date());

            listEmployee = employeeStore.NCURPKS_LISTOFTABN100BDAY(getLogin().getModule(), getLogin().getCompanyNo(), 1, Util.toSQLDate(new Date()), Util.toSQLDate(new Date()), getLogin().getUserName());

            return listEmployee;

        } catch (Exception e) {
            return null;
        }
    }

    public void getListB630Detail(int id) {
        try {
            try {
                List<B630> listB630Edit = getListAllN630();
                if (listB630Edit.size() > 0) {
                    for (int i = 0; i < listB630Edit.size(); i++) {
                        if (listB630Edit.get(i).getPb630() == id) {
                            this.bv631 = listB630Edit.get(i).getBv631();
                            this.bv635 = listB630Edit.get(i).getBv635();
                            this.bv636 = listB630Edit.get(i).getBv636();
                            this.bd632 = listB630Edit.get(i).getBd632();
                            this.bd633 = listB630Edit.get(i).getBd633();
                            this.fb050 = listB630Edit.get(i).getFb050();
                            this.fb670 = listB630Edit.get(i).getFb670();
                            this.fq100 = listB630Edit.get(i).getFq100();

                            //this.fn850dt = listB630Edit.get(i).get
                            this.fk100 = listB630Edit.get(i).getFk100();
                            System.out.println("------- OUT---" + fk100 + fq100);
                            break;
                        }
                    }
                }
            } catch (Exception ex) {
                System.out.println("Error when getDetailEditN850. ERROR CODE: " + ex.getMessage());
            }
        } catch (Exception e) {
        }
    }
    private List<B630> listControlerDate;

    public void reloadlist(ActionEvent ac) {
        System.out.println("ActionEvent--" + loginEmp);
        SessionProvider.setSessionMapValue("TYPE", 0);
        userAction = loginEmp;
        SessionProvider.setSessionMapValue("typeSearchCSKHCT", 0);
        SessionProvider.setSessionMapValue("keySearchCSKHCT", null);
        SessionProvider.setSessionMapValue("typeSearchCSKH", 0);
        SessionProvider.setSessionMapValue("keySearchCSKH", null);
        SessionProvider.setSessionMapValue("emp", loginEmp);
    }

    public List<B630> getListByDate(Date date) {
        try {
            if (listB630 == null) {
                System.out.println("list b630---" + this.pb630 + "," + "null" + "," + "null," + ",AC" + fc500 + "," + fb670 + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFq100() + "," + 0 + "," + this.getFn100() + "," + getLogin().getUserName());
                if (this.pageRidiect.equals("customer.jsp")) {
                    listB630 = b630Store.getListAllB630(this.pb630, date, null, this.bv639, fc500, fb670, getLogin().getModule(), getLogin().getCompanyNo(), getFq100(), 0, getFn100(), getLogin().getUserName());
                    listOfDateCM = listB630;
                } else {
                    System.out.println("Cong ty ");
                    System.out.println("list b630 congty---" + this.pb630 + "," + date + "," + "null" + ",AC" + "," + 0 + "," + fb670 + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFk100() + "," + 0 + "," + this.getFn100() + "," + getLogin().getUserName());
                    // listB630 = b630Store.getListAllB630COM(this.pb630, date, null, this.bv639, 0, fc500, fb670, getLogin().getModule(), getLogin().getCompanyNo(), getFk100(), 0, getFn100(), getLogin().getUserName());
                    listOfDateCOM = listB630;
                }
                Iterator ic = listB630.iterator();
                while (ic.hasNext()) {
                    B630 b630 = (B630) ic.next();
                    this.pb630 = b630.getPb630();
                    this.bv631 = b630.getBv631();
                    this.bd632 = b630.getBd632();
                    this.bd633 = b630.getBd633();
                    this.bv636 = b630.getBv636();
                    this.bc637 = b630.getBc637();
                    this.fc500 = b630.getFc500();
                    this.fb670 = b630.getFb670();
                    this.fk100 = b630.getFk100();
                    this.fn100 = b630.getFn100();
                    this.fq100 = b630.getFq100();
                    this.kv103 = b630.getKv103();

                }

            }
            System.out.println("------size-----" + listB630.size());
            return listB630;
        } catch (Exception ex) {
            return null;
        }
    }
    private String stDate = "";
    private StringBuffer buffer = new StringBuffer();
    private StringBuffer buffer2 = new StringBuffer();

    public String getDateOfGroup() {
        try {
            Map<Date, List<B630>> map = new HashMap<Date, List<B630>>();
            List<B630> listNew;
            Iterator ic = getListAllN630().iterator();
//         if (this.pageRidiect.equals("customer.jsp")) {
//         ic = b630Store.getListAllB630(this.pb630, null, null, this.bv639, fc500, fb670, getLogin().getModule(), getLogin().getCompanyNo(), getFq100(), 0, getFn100(), getLogin().getUserName()).iterator();
//         }else{
//             ic = b630Store.getListAllB630COM(this.pb630, null, null, this.bv639, 0, fc500, fb670, getLogin().getModule(), getLogin().getCompanyNo(), getFk100(), 0, getFn100(), getLogin().getUserName()).iterator(); 
//         }
            List<B630> listdemo = new ArrayList<B630>();
            while (ic.hasNext()) {
                B630 b6 = (B630) ic.next();
                List<B630> listofDate = new ArrayList<B630>();
                Date date = b6.getBd632();

                listofDate.add(b6);
                List<B630> listRenew = new ArrayList<B630>();
                map.put(date, listofDate);
                listdemo.add(b6);
                //System.out.println("danh sach hien thi "+ listofDate.get(0).getBv631());

            }

//            for (int i = 0; i < listdemo.size(); i++) {
//                for (int j = i + 1; j < listdemo.size(); j++) {
//                    B630 stb = listdemo.get(i);
//                    B630 sts = listdemo.get(j);
//                    if (stb.getBd632().equals(sts.getBd632())) {
//                        System.out.println("so lan dung " + stb.getBd632());
//                        getBuffer().append(stb.getBd632().toString());
//                      
//                       getBuffer().append(sts.getBv631().toString());
//                        System.out.println("-----------------stadate------" + stDate);
//
//                    }else{
//                        
//                    }
//              }

            //  }
            listNew = new ArrayList(map.entrySet());
            Iterator iterator = map.entrySet().iterator();
            while (iterator.hasNext()) {

                Map.Entry mapEntry = (Map.Entry) iterator.next();
                Date date = (Date) mapEntry.getKey();
                listControlerDate = new ArrayList<B630>();
                System.out.println("Ngay thang " + mapEntry.getKey());
                buffer.append(mapEntry.getKey());
                System.out.println("Hien thi " + mapEntry.getValue());
//              B630Controller bnew = new B630Controller();
//              bnew.setBd632(date);
//              listNew.add(bnew);
                List<B630> listbuffer = (List<B630>) mapEntry.getValue();
                Iterator ibufer = listbuffer.iterator();
                while (ibufer.hasNext()) {
                    B630 bbufer = (B630) ibufer.next();
                    System.out.println("buuuuuuuuuuu" + bbufer.getBv631());
                    if (mapEntry.equals(bbufer.getBd632())) {
                        buffer2.append(bbufer.getBv631());
                    }
                }
                listControlerDate = getListByDate(date);
//
            }

            StringBuffer b = new StringBuffer();
            b.append(buffer);
            b.append(buffer2);
            stDate += b;
            System.out.println("-----------------stadate------" + stDate);
            return stDate;
        } catch (Exception ex) {
            return null;
        }
    }

    public List<B630> getListB630GroupDate() {
        try {
            Map<Date, List<B630>> map = new HashMap<Date, List<B630>>();
            List<B630> listNew;
            Iterator ic = getListAllN630().iterator();
            List<B630> removes = new ArrayList<B630>();
            while (ic.hasNext()) {
                B630 b6 = (B630) ic.next();
                List<B630> listofDate = new ArrayList<B630>();
                Date date = b6.getBd632();
                // listofDate.add(b6);
                removes.add(b6);
                List<B630> listRenew = new ArrayList<B630>();
                listRenew = getListAllN630();
                // listRenew.removeAll(removes);
                for (int i = 0; i < listRenew.size(); i++) {
                    B630 stnew = listRenew.get(i);
                    if (date.equals(stnew.getBd632())) {
                        listofDate.add(stnew);
                        removes.add(stnew);
                    }
                }
                map.put(date, listofDate);


            }


            listNew = new ArrayList(map.entrySet());
            Iterator iterator = map.entrySet().iterator();
            while (iterator.hasNext()) {

                Map.Entry mapEntry = (Map.Entry) iterator.next();
                Date date = (Date) mapEntry.getKey();
                listControlerDate = new ArrayList<B630>();
                System.out.println("Ngay thang " + mapEntry.getKey());
                System.out.println("Hien thi " + mapEntry.getValue());
//              B630Controller bnew = new B630Controller();
//              bnew.setBd632(date);
//              listNew.add(bnew);
                listControlerDate = getListByDate(date);
//
            }
//            stDate += buffer;
//            System.out.println("-----------------stadate------" + stDate);
            return listNew;
        } catch (Exception ex) {
            System.out.println("---errrrrrr" + ex.getMessage());
            return null;
        }
    }

    public void changeCombN850forN900(ValueChangeEvent event) {
        // this.fn850dt = Integer.parseInt(event.getNewValue().toString());
        System.out.println("---------evient fn850-----------" + event.getNewValue());
        selectItemN900 = comboboxUtil.getSelectedN900CombID(Integer.parseInt(event.getNewValue().toString()));

    }

    public List<B630> getListNote() {
        try {
            System.out.println("getListNote--" + pb630);
            List<B630> lstNote = b630Store.LISTOFTABB650(getLogin().getModule(), getLogin().getCompanyNo(), pb630, getLogin().getUserName());
            System.out.println("getListNote--" + lstNote.size());
            return lstNote;
        } catch (Exception e) {
            System.out.println("Error when getListNote. ERROR CODE: " + e.getMessage());
            return null;
        }

    }

    private void getListB650Detail(int id) {
        try {
            List<B630> listB630Edit = getListNote();
            System.out.println("listB630Edit--" + listB630Edit.size());
            if (listB630Edit.size() > 0) {
                for (int i = 0; i < listB630Edit.size(); i++) {
                    if (listB630Edit.get(i).getPb650() == id) {
                        this.bv651 = listB630Edit.get(i).getBv651();
                        this.bv652 = listB630Edit.get(i).getBv652();
                        this.pb630 = listB630Edit.get(i).getFb630();
                        this.bl667 = listB630Edit.get(i).getBl667();
                        System.out.println("------- OUT---" + pb650);
                        break;
                    }
                }
            }

        } catch (Exception e) {
            System.out.println("Error when getListB650Detail. ERROR CODE: " + e.getMessage());
        }
    }

    public void updateB650() {
        int rs = 0;
        try {
            System.out.println("INSERTTABB650--:" + pb650 + "','" + bv651 + "','" + bv652 + "','" + pb630 + "','" + getLogin().getUserName());
            rs = b630Inf.INSERTTABB650(pb650, bv651, bv652, pb630, getLogin().getUserName());
            System.out.println("updateB650 rs--" + rs + "--pageRidiect--" + pageRidiect);
        } catch (Exception e) {
            rs = -1;
        }
        if (rs > 0) {
            showGlobalReport(true, getResourceString("datasavesuccessful"));

        } else {
            showGlobalReport(true, getResourceString("datasuccessfail"));
        }
        if (pageRidiect.equals("customer.jsp")) {
            sendRedirectURL(pageRidiect, fn100, 4);
        } else if (pageRidiect.equals("cuscompany.jsp")) {
            sendRedirectURL(pageRidiect, fn100, 5);

        } else {
            sendRedirect(pageRidiect);
        }


    }

    //Hien thi danh sanh muc dich lua chon danh sach cong viec khach hang
    public List<SelectItem> getListComB670() {
        if (listComB670 != null && listComB670.size() > 0) {
        } else {
            listComB670 = comboboxUtil.getListCombB670();
        }
        return listComB670;
    }

    //Hien thi danh sach cong ty
    public List<SelectItem> getListCombK100() {

        return comboboxUtil.getListCombK100();
    }

    //Danh sach nguoi dai dien
    public List<SelectItem> getListCombN100D() {
        System.out.println("--------k100-n100------" + fk100);

        System.out.println("--------size 00-n100------" + comboboxUtil.getListCombN100D(fk100).size());
        return comboboxUtil.getListCombN100D(fk100);
    }

    public List<SelectItem> getSelectComN100D() {
        selectComN100D = comboboxUtil.getListCombN100D(fk100);
        return selectComN100D;
    }

    /**
     * @return the selectCombN850
     */
    public List<SelectItem> getSelectCombN850() {
        if (selectCombN850 != null && selectCombN850.size() > 0) {
        } else {
            selectCombN850 = comboboxUtil.getSelectedN850Comb();

        }

        return selectCombN850;
    }

    /**
     * @return the bv631
     */
    public String getBv631() {
        return bv631;
    }

    /**
     * @param bv631 the bv631 to set
     */
    public void setBv631(String bv631) {
        this.bv631 = bv631;
    }

    /**
     * @return the fc500
     */
    public int getFc500() {
        return fc500;
    }

    /**
     * @param fc500 the fc500 to set
     */
    public void setFc500(int fc500) {
        this.fc500 = fc500;
    }

    /**
     * @return the bd632
     */
    public Date getBd632() {
        return bd632;
    }

    /**
     * @param bd632 the bd632 to set
     */
    public void setBd632(Date bd632) {
        this.bd632 = bd632;
    }

    /**
     * @return the bd633
     */
    public Date getBd633() {
        return bd633;
    }

    /**
     * @param bd633 the bd633 to set
     */
    public void setBd633(Date bd633) {
        this.bd633 = bd633;
    }

    /**
     * @return the bn634
     */
    public int getBn634() {
        return bn634;
    }

    /**
     * @param bn634 the bn634 to set
     */
    public void setBn634(int bn634) {
        this.bn634 = bn634;
    }

    /**
     * @return the bv635
     */
    public String getBv635() {
        return bv635;
    }

    /**
     * @param bv635 the bv635 to set
     */
    public void setBv635(String bv635) {
        this.bv635 = bv635;
    }

    /**
     * @return the bv636
     */
    public String getBv636() {
        return bv636;
    }

    /**
     * @param bv636 the bv636 to set
     */
    public void setBv636(String bv636) {
        this.bv636 = bv636;
    }

    /**
     * @return the bc637
     */
    public String getBc637() {
        return bc637;
    }

    /**
     * @param bc637 the bc637 to set
     */
    public void setBc637(String bc637) {
        this.bc637 = bc637;
    }

    /**
     * @return the bc638
     */
    public String getBc638() {
        return bc638;
    }

    /**
     * @param bc638 the bc638 to set
     */
    public void setBc638(String bc638) {
        this.bc638 = bc638;
    }

    /**
     * @return the fb670
     */
    public int getFb670() {
        return fb670;
    }

    /**
     * @param fb670 the fb670 to set
     */
    public void setFb670(int fb670) {
        this.fb670 = fb670;
    }

    /**
     * @return the fh000
     */
    public int getFh000() {
        return fh000;
    }

    /**
     * @param fh000 the fh000 to set
     */
    public void setFh000(int fh000) {
        this.fh000 = fh000;
    }

    /**
     * @return the fh200
     */
    public int getFh200() {
        return fh200;
    }

    /**
     * @param fh200 the fh200 to set
     */
    public void setFh200(int fh200) {
        this.fh200 = fh200;
    }

    /**
     * @return the fk100
     */
    public int getFk100() {
        return fk100;
    }

    /**
     * @param fk100 the fk100 to set
     */
    public void setFk100(int fk100) {
        this.fk100 = fk100;
    }

    /**
     * @return the fb050
     */
    public int getFb050() {
        return fb050;
    }

    /**
     * @param fb050 the fb050 to set
     */
    public void setFb050(int fb050) {
        this.fb050 = fb050;
    }

    /**
     * @return the fn100
     */
    public int getFn100() {
        return fn100;
    }

    /**
     * @param fn100 the fn100 to set
     */
    public void setFn100(int fn100) {
        this.fn100 = fn100;
    }

    /**
     * @return the fq101
     */
    public String getFq101() {
        return fq101;
    }

    /**
     * @param fq101 the fq101 to set
     */
    public void setFq101(String fq101) {
        this.fq101 = fq101;
    }

    /**
     * @return the b630Inf
     */
    public B630Inf getB630Inf() {
        return b630Inf;
    }

    /**
     * @param b630Inf the b630Inf to set
     */
    public void setB630Inf(B630Inf b630Inf) {
        this.b630Inf = b630Inf;
    }

    /**
     * @return the selectItemN900
     */
    public List<SelectItem> getSelectItemN900() {
        return selectItemN900;
    }

    /**
     * @param selectItemN900 the selectItemN900 to set
     */
    public void setSelectItemN900(List<SelectItem> selectItemN900) {
        this.selectItemN900 = selectItemN900;
    }

    /**
     * @param selectCombN850 the selectCombN850 to set
     */
    public void setSelectCombN850(List<SelectItem> selectCombN850) {
        this.selectCombN850 = selectCombN850;
    }

    /**
     * @return the fn850dt
     */
    public int getFn850dt() {

        return fn850dt = 3;
    }

    /**
     * @param fn850dt the fn850dt to set
     */
    public void setFn850dt(int fn850dt) {
        this.fn850dt = fn850dt;
    }

    /**
     * @return the pb670
     */
    public int getPb670() {
        return pb670;
    }

    /**
     * @param pb670 the pb670 to set
     */
    public void setPb670(int pb670) {
        this.pb670 = pb670;
    }

    /**
     * @return the companyName
     */
    public String getCompanyName() {
        setCompanyName(comboboxUtil.getListCombK100().get(0).getLabel().toString());
        return companyName;
    }

    /**
     * @param companyName the companyName to set
     */
    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    /**
     * @return the pb630
     */
    public int getPb630() {
        return pb630;
    }

    /**
     * @param pb630 the pb630 to set
     */
    public void setPb630(int pb630) {
        this.pb630 = pb630;
    }

    /**
     * @return the bv639
     */
    public String getBv639() {
        return bv639;
    }

    /**
     * @param bv639 the bv639 to set
     */
    public void setBv639(String bv639) {
        this.bv639 = bv639;
    }

    /**
     * @return the fq100
     */
    public int getFq100() {
        return fq100;
    }

    /**
     * @param fq100 the fq100 to set
     */
    public void setFq100(int fq100) {
        this.fq100 = fq100;
    }

    /**
     * @return the pageRidiect
     */
    public String getPageRidiect() {
        return pageRidiect;
    }

    /**
     * @param pageRidiect the pageRidiect to set
     */
    public void setPageRidiect(String pageRidiect) {
        this.pageRidiect = pageRidiect;
    }

    /**
     * @return the flagcus
     */
    public boolean isFlagcus() {
        return flagcus;
    }

    /**
     * @param flagcus the flagcus to set
     */
    public void setFlagcus(boolean flagcus) {
        this.flagcus = flagcus;
    }

    /**
     * @return the flagcom
     */
    public boolean isFlagcom() {
        return flagcom;
    }

    /**
     * @param flagcom the flagcom to set
     */
    public void setFlagcom(boolean flagcom) {
        this.flagcom = flagcom;
    }

    /**
     * @return the displaycus
     */
    public String getDisplaycus() {
        return displaycus;
    }

    /**
     * @param displaycus the displaycus to set
     */
    public void setDisplaycus(String displaycus) {
        this.displaycus = displaycus;
    }

    /**
     * @return the displaycom
     */
    public String getDisplaycom() {
        return displaycom;
    }

    /**
     * @param displaycom the displaycom to set
     */
    public void setDisplaycom(String displaycom) {
        this.displaycom = displaycom;
    }

    /**
     * @return the selectComN100D
     */
    /**
     * @param selectComN100D the selectComN100D to set
     */
    public void setSelectComN100D(List<SelectItem> selectComN100D) {
        this.selectComN100D = selectComN100D;
    }

    /**
     * @return the kv103
     */
    public String getKv103() {
        return kv103;
    }

    /**
     * @param kv103 the kv103 to set
     */
    public void setKv103(String kv103) {
        this.kv103 = kv103;
    }

    /**
     * @return the listControlerDate
     */
    public List<B630> getListControlerDate() {
        return listControlerDate;
    }

    /**
     * @param listControlerDate the listControlerDate to set
     */
    public void setListControlerDate(List<B630> listControlerDate) {
        this.listControlerDate = listControlerDate;
    }

    /**
     * @return the listOfDateCM
     */
    public List<B630> getListOfDateCM() {
        return listOfDateCM;
    }

    /**
     * @param listOfDateCM the listOfDateCM to set
     */
    public void setListOfDateCM(List<B630> listOfDateCM) {
        this.listOfDateCM = listOfDateCM;
    }

    /**
     * @return the listOfDateCOM
     */
    public List<B630> getListOfDateCOM() {
        return listOfDateCOM;
    }

    /**
     * @param listOfDateCOM the listOfDateCOM to set
     */
    public void setListOfDateCOM(List<B630> listOfDateCOM) {
        this.listOfDateCOM = listOfDateCOM;
    }

    /**
     * @return the stDate
     */
    public String getStDate() {

        return stDate;
    }

    /**
     * @param stDate the stDate to set
     */
    public void setStDate(String stDate) {
        this.stDate = stDate;
    }

    /**
     * @return the buffer
     */
    public StringBuffer getBuffer() {
        return buffer;
    }

    /**
     * @param buffer the buffer to set
     */
    public void setBuffer(StringBuffer buffer) {
        this.buffer = buffer;
    }

    /**
     * @return the buffer2
     */
    public StringBuffer getBuffer2() {
        return buffer2;
    }

    /**
     * @param buffer2 the buffer2 to set
     */
    public void setBuffer2(StringBuffer buffer2) {
        this.buffer2 = buffer2;
    }

    /**
     * @return the combB050
     */
    public List<SelectItem> getCombB050() {
        if (combB050 != null && combB050.size() > 0) {
        } else {
            combB050 = comboboxUtil.getListCombB050();
        }

        return combB050;
    }

    /**
     * @param combB050 the combB050 to set
     */
    public void setCombB050(List<SelectItem> combB050) {
        this.combB050 = combB050;
    }

    /**
     * @return the bn640
     */
    public int getBn640() {
        return bn640;
    }

    /**
     * @param bn640 the bn640 to set
     */
    public void setBn640(int bn640) {
        this.bn640 = bn640;
    }

    /**
     * @return the checkComplete
     */
    public boolean isCheckComplete() {
        return checkComplete;
    }

    /**
     * @param checkComplete the checkComplete to set
     */
    public void setCheckComplete(boolean checkComplete) {
        this.checkComplete = checkComplete;
    }

    /**
     * @return the NV106
     */
    public String getNV106() {
        return NV106;
    }

    /**
     * @param NV106 the NV106 to set
     */
    public void setNV106(String NV106) {
        this.NV106 = NV106;
    }

    /**
     * @return the typeSearch
     */
    public int getTypeSearch() {
        return typeSearch;
    }

    /**
     * @param typeSearch the typeSearch to set
     */
    public void setTypeSearch(int typeSearch) {
        this.typeSearch = typeSearch;
    }

    /**
     * @return the pb650
     */
    public int getPb650() {
        return pb650;
    }

    /**
     * @param pb650 the pb650 to set
     */
    public void setPb650(int pb650) {
        this.pb650 = pb650;
    }

    /**
     * @return the bv651
     */
    public String getBv651() {
        return bv651;
    }

    /**
     * @param bv651 the bv651 to set
     */
    public void setBv651(String bv651) {
        this.bv651 = bv651;
    }

    /**
     * @return the bv652
     */
    public String getBv652() {
        return bv652;
    }

    /**
     * @param bv652 the bv652 to set
     */
    public void setBv652(String bv652) {
        this.bv652 = bv652;
    }

    /**
     * @return the bl667
     */
    public String getBl667() {
        return bl667;
    }

    /**
     * @param bl667 the bl667 to set
     */
    public void setBl667(String bl667) {
        this.bl667 = bl667;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @param listComB670 the listComB670 to set
     */
    public void setListComB670(List<SelectItem> listComB670) {
        this.listComB670 = listComB670;
    }

    /**
     * @return the listSelectedCM
     */
    public List<B630> getListSelectedCM() {
        return listSelectedCM;
    }

    /**
     * @param listSelectedCM the listSelectedCM to set
     */
    public void setListSelectedCM(List<B630> listSelectedCM) {
        this.listSelectedCM = listSelectedCM;
    }

    /**
     * @return the listSelectedCOM
     */
    public List<B630> getListSelectedCOM() {
        return listSelectedCOM;
    }

    /**
     * @param listSelectedCOM the listSelectedCOM to set
     */
    public void setListSelectedCOM(List<B630> listSelectedCOM) {
        this.listSelectedCOM = listSelectedCOM;
    }

    public Boolean checkExistList(List<B630> list, int index) {
        for (B630 b630 : list) {
            if (b630.getPb630() == index) {
                return true;
            }
        }
        return false;
    }

    //paging
    /**
     * @return the Offset
     */
    public int getOffset() {
        return Offset;
    }

    /**
     * @param Offset the Offset to set
     */
    public void setOffset(int Offset) {
        this.Offset = Offset;
    }

    /**
     * @return the Limit
     */
    public int getLimit() {
        return Limit;
    }

    /**
     * @param Limit the Limit to set
     */
    public void setLimit(int Limit) {
        this.Limit = Limit;
    }

    // property for paging
    /**
     * @return the current
     */
    public int getCurrent() {
        if (current > totalpage) {
            current = totalpage;
        } else if (current < 1) {
            current = 1;
        }
        return current;
    }

    /**
     * @param current the current to set
     */
    public void setCurrent(int current) {

        start = (current - 1) * getNumrow();
        end = current * numrow;
        this.current = current;
    }

    /**
     * @return the numrow
     */
    public int getNumrow() {
        if (numrow == 0) {
            numrow = 30;
        }
        return numrow;
    }

    /**
     * @param numrow the numrow to set
     */
    public void setNumrow(int numrow) {
        this.numrow = numrow;
    }

    /**
     * @return the start
     */
    public int getStart() {
        if (start == 0) {
            start = 1;
        }
        return start;
    }

    /**
     * @param start the start to set
     */
    public void setStart(int start) {
        this.start = start;
    }

    /**
     * @return the end
     */
    public int getEnd() {
        if (end == 0) {
            end = 20;
        }
        return end;
    }

    /**
     * @param end the end to set
     */
    public void setEnd(int end) {
        this.end = end;
    }

    /**
     * @return the totalrow
     */
    public int getTotalrow() {
        return totalrow;
    }

    /**
     * @param totalrow the totalrow to set
     */
    public void setTotalrow(int totalrow) {
//        if (totalrow == 0) {
//            totalrow = 100;
//        }
        totalpage = totalrow / numrow;

        if (totalrow % numrow > 0) {
            totalpage = totalpage + 1;
        }


        if (getTotalpage() <= 10) {
            setStartpage(1);
            setEndpage(getTotalpage());

        } else {
            setStartpage(current - 5);
            setEndpage(current + 5);


        }
        this.totalrow = totalrow;
    }

    /**
     * @return the startpage
     */
    public int getStartpage() {
        if (startpage < 1) {
            startpage = 1;
        }
        return startpage;
    }

    /**
     * @param startpage the startpage to set
     */
    public void setStartpage(int startpage) {
        this.startpage = startpage;
    }

    /**
     * @return the endpage
     */
    public int getEndpage() {
        if (endpage > totalpage) {
            endpage = totalpage;
        }
        return endpage;
    }

    /**
     * @param endpage the endpage to set
     */
    public void setEndpage(int endpage) {

        this.endpage = endpage;
    }

    /**
     * @return the totalpage
     */
    public int getTotalpage() {
//        if (totalpage == 0) {
//            totalpage = 10;
//        }
        return totalpage;
    }

    /**
     * @param totalpage the totalpage to set
     */
    public void setTotalpage(int totalpage) {
        this.totalpage = totalpage;
    }

    /**
     * @return the pagename
     */
    public String getPagename() {
        return pagename;
    }

    /**
     * @param pagename the pagename to set
     */
    public void setPagename(String pagename) {
        this.pagename = pagename;
    }

    /**
     * @return the totalcurent
     */
    public int getTotalcurent() {
        return totalcurent;
    }

    /**
     * @param totalcurent the totalcurent to set
     */
    public void setTotalcurent(int totalcurent) {
        this.totalcurent = totalcurent;
    }

    /**
     * @return the keySearch
     */
    public String getKeySearch() {
        return keySearch;
    }

    /**
     * @param keySearch the keySearch to set
     */
    public void setKeySearch(String keySearch) {
        this.keySearch = keySearch;
    }

    /**
     * @return the lstEmpByID
     */
    public List<SelectItem> getLstEmpByID() {
        String emp = loginEmp;
        try {
            if (lstEmpByID == null || lstEmpByID.size() < 1) {
                lstEmpByID = comboboxUtil.getSelectedN900Comb(fn850);
                for (int i = 0; i < lstEmpByID.size(); i++) {
                    if (lstEmpByID.get(i).getValue().toString().equals(loginEmp)) {
                        //neu nhan vien dc chon co trong nhom to
                        emp = lstEmpByID.get(i).getValue().toString();
                        break;
                    } else {//neu ko co thi gan la ng dau tien
                        emp = lstEmpByID.get(0).getValue().toString();
                    }
                }
                loginEmp = emp;
                if (flagFN850 == 10) {
                    userAction = emp;
                }
                SessionProvider.setSessionMapValue("emp", loginEmp);
            }

        } catch (Exception e) {
            System.out.println("getLstEmpByID error--:" + e.getMessage());
            lstEmpByID = new ArrayList<SelectItem>();
        }

        System.out.println("getLstEmpByID-size-" + lstEmpByID.size() + "---fn850--" + fn850 + "--emplogin--" + loginEmp + "--userAction--" + userAction);
        return lstEmpByID;
    }

    /**
     * @param lstEmpByID the lstEmpByID to set
     */
    public void setLstEmpByID(List<SelectItem> lstEmpByID) {
        this.lstEmpByID = lstEmpByID;
    }

    /**
     * @return the fn850
     */
    public int getFn850() {
        return fn850;
    }

    /**
     * @param fn850 the fn850 to set
     */
    public void setFn850(int fn850) {
        this.fn850 = fn850;
    }

    /**
     * @return the loginEmp
     */
    public String getLoginEmp() {
        return loginEmp;
    }

    /**
     * @param loginEmp the loginEmp to set
     */
    public void setLoginEmp(String loginEmp) {
        this.loginEmp = loginEmp;
    }

    /**
     * @return the userAction
     */
    public String getUserAction() {
        return userAction;
    }

    /**
     * @param userAction the userAction to set
     */
    public void setUserAction(String userAction) {
        this.userAction = userAction;
    }

    /**
     * @return the flagFN850
     */
    public int getFlagFN850() {
        return flagFN850;
    }

    /**
     * @param flagFN850 the flagFN850 to set
     */
    public void setFlagFN850(int flagFN850) {
        this.flagFN850 = flagFN850;
    }

    /**
     * @return the actionChange
     */
    public String getActionChange() {
        return actionChange;
    }

    /**
     * @param actionChange the actionChange to set
     */
    public void setActionChange(String actionChange) {
        this.actionChange = actionChange;
    }

    /**
     * @return the listhistoryCustomer
     */
    public List<B630> getListhistoryCustomer() {
        try {
           
            if (SessionProvider.getSessionMapValue("PN100HD") != null) {
                fq100 = Util.parseInt(SessionProvider.getSessionMapValue("PN100HD"));
            }           
            listhistoryCustomer = b630Store.getListB630CN(this.getPb630(), null, null, this.getBv639(), this.getBn640(), this.getFc500(), 0, getLogin().getModule(), getLogin().getCompanyNo(), 0, 0, this.fq100, getLogin().getUserName());
             System.out.println("---Khách hàng cá nhân--" + fq100 + "--getListB630CN----" + this.getPb630() + "," + null + "," + null + "," + this.getBv639() + "," + this.getBn640() + "," + this.getFc500() + "," + this.getFb670() + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFk100() + "," + this.getFb050() + "," + fq100 + "," + getLogin().getUserName());
            return listhistoryCustomer;
        } catch (Exception e) {
            return null;
        }

    }

    /**
     * @param listhistoryCustomer the listhistoryCustomer to set
     */
    public void setListhistoryCustomer(List<B630> listhistoryCustomer) {
        this.listhistoryCustomer = listhistoryCustomer;
    }
}
